package it.gestionedocumentale.hibernate.dao;



import it.gestionedocumentale.model.Tag;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

public class TagDAO extends BaseHibernateDAO{
	
	
	
	// property constants
	public static final String COD_TAG = "codTag";
	public static final String DESCRIZIONE = "descrizione";
	

	public void save(Tag transientInstance) throws Exception{
		getSession().save(transientInstance);
	}
	
	public void update(Tag transientInstance) throws Exception{
		getSession().saveOrUpdate(transientInstance);
	}

	public void delete(Tag persistentInstance) throws Exception{
		getSession().delete(persistentInstance);
	}

	public Tag findById(Long id) throws Exception{
		Tag instance = (Tag) getSession().get(Tag.class, id);
		return instance;
	}

	@SuppressWarnings("unchecked")
	public List<Tag> findByExample(Tag instance) throws Exception{
		Criteria cri = getSession().createCriteria(Tag.class);
		cri.add(Example.create(instance));
		List<Tag> results = cri.list();
		return results;
	}
	
	@SuppressWarnings("unchecked")
	public List<Tag> findAll() throws Exception{
		String queryString = "from Tag";
		Query queryObject = getSession().createQuery(queryString);
		return queryObject.list();
	}

	@SuppressWarnings("unchecked")
	public List<Tag> findByProperty(String propertyName, Object value) throws Exception{
		String queryString = "from Tag as model where model." + propertyName
				+ "= ?";
		Query queryObject = getSession().createQuery(queryString);
		queryObject.setParameter(0, value);
		return queryObject.list();
	}
	
	public List<Tag> findByCodTag(Object codTag) throws Exception{
		return findByProperty(COD_TAG, codTag);
	}
	
	public List<Tag> findByDescription(Object descrizione) throws Exception{
		return findByProperty(DESCRIZIONE, descrizione);
	}
	
		public Tag merge(Tag detachedInstance) throws Exception{
		Tag result = (Tag) getSession().merge(detachedInstance);
		return result;
	}


}
